package com.cn.study.third.stage.codezuoye1;

public class Statistics {
    public static void main(String[] args) {
        String str1 = new String("ABCD123!@#$%ab");

        System.out.println("字符串： " + str1);


        int n1 = 0; //记录数字字符的总个数

        int n2 = 0; //记录大写字母的总个数

        int n3 = 0; //记录小写字母的总个数

        int n4 = 0; //记录其他字符的总个数


        StringBuilder sb1 = new StringBuilder(); // 记录数字字符

        StringBuilder sb2 = new StringBuilder(); // 记录大写字母

        StringBuilder sb3 = new StringBuilder(); // 记录小写字母

        StringBuilder sb4 = new StringBuilder(); // 记录其他字符


// 打印每个字符对应的ASCII

        System.out.print("打印每个字符对应的ASCII: ");

        for (char c : str1.toCharArray()) {

            System.out.print(c + "|" + (byte) c + " ");

        }


        System.out.println();


//判别字符所属类别并打印出来

        for (byte b : str1.getBytes()) {

            if (b >= 48 && b <= 57) {// 判别数字字符

                sb1.append((char) b);

                n1++;

            } else if (b >= 65 && b <= 90) {// 判别大写字母

                sb2.append((char) b);

                n2++;

            } else if (b >= 97 && b <= 122) {// 判别小写字母

                sb3.append((char) b);

                n3++;

            } else {// 其他字符

                sb4.append((char) b);

                n4++;

            }

        }

        System.out.println("数字字符总个数：" + n1 + ", " + "它们是：" + sb1);

        System.out.println("大写字母字符总个数：" + n2 + ", " + "它们是：" + sb2);

        System.out.println("小写字母字符总个数：" + n3 + ", " + "它们是：" + sb3);

        System.out.println("其他字符总个数：" + n4 + ", " + "它们是：" + sb4);

    }
}
